********************************************************************************
*
*	Date: May 21 2024 
*	This do-file replicates all tables and figures in: 
*	Karoline Larsen Kolstad. 2024. Overburdened Bureaucrats: Providing Equal Access to Public Services during Covid-19.
*	
*	by conducting all analysis based on data from Statistics Denmark reported in the manuscript. 
*
*	To produce all results four datasets are needed
*	1) aggregate_unemployment 
*	2) aggregate_main
*	3) micro_main
*	4) micro_duration
*
********************************************************************************

cd "E:\workdata\708030\JOP_article"

log using "log_manuscript.smcl", replace  

********************************************************************************
********************************************************************************
*Data
use "data/aggregate_unemployment.dta", clear
tsset year_week, weekly

*Figure 1: Number of Unemployed
tsline unemp_all, xline(3130 3141, lcolor(black*0.8) lp(dash) lwidth(vthin)) ylabel(4400(200)5400, labsize(small) nogrid) xlabel(3016 3040 3068 3097 3126 3155, labsize(small) nogrid) title("") graphregion(color(white)) ytitle("Number of unemployed", size(medium)) xtitle("Year, week", size(medium)) recast(line) recast(line) lwidth(thin) lcolor(black) ysc(titlegap(+3)) || (pcarrowi 5200 3125 5200 3130 (9) "Lockdown" 5400 3145 5400 3141 (3) "Reopening", color(black) mlabcolor(black)), legend(off) 
qui graph export "output\fig_1_unemployment.png", replace

*Figure 2: Adjusted Unemployment, Selected Industries
tsline unemp_adj_industry_4 unemp_adj_industry_11 unemp_adj_industry_13 unemp_adj_industry_15 if year_week >3086, xline(3130 3141, lcolor(black) lp(dash) lwidth(vthin)) ylabel(-1(2)9, labsize(small) nogrid) xlabel(3086 3105 3129 3155, labsize(small) nogrid) title("{bf: (a) Unexposed industries}", size(medium) color(black)) graphregion(color(white)) ytitle("Adjusted unemployment", size(medium)) xtitle("Year, week", size(medium)) recast(line) lwidth(thin) lpattern(solid dot dash_dot shortdash_dot longdash) lcolor(black black black black) legend(order(1 "Energi supply" 2 "Finance and insurance" 3 "Knowledge service" 4 "Defense and police") size(small) symxsize(7)) ysc(titlegap(+3)) || (pcarrowi 5 3125 5 3130 (9) "Lockdown" 7 3145 7 3141 (3) "Reopening", color(black) mlabcolor(black)), saving(output\unemp_industry_low.gph, replace) 

tsline unemp_adj_industry_8 unemp_adj_industry_9 unemp_adj_industry_14 unemp_adj_industry_18 if year_week >3086, xline(3130 3141, lcolor(black) lp(dash) lwidth(vthin)) ylabel(-1(2)9, labsize(small) nogrid) xlabel(3086 3105 3129 3155, labsize(small) nogrid) title("{bf: (b) Exposed industries}", size(medium) color(black)) graphregion(color(white)) ytitle("", size(medium)) xtitle("Year, week", size(medium)) recast(line) lwidth(thin) lpattern(solid dot dash_dot shortdash_dot longdash) lcolor(black black black black) legend(order(1 "Transport" 2 "Hotels and restaurants"  3 "Traveling" 4 "Culture and leisure") size(small) symxsize(7)) || (pcarrowi 5 3125 5 3130 (9) "Lockdown" 7 3145 7 3141 (3) "Reopening", color(black) mlabcolor(black)), saving(output\unemp_industry_high.gph, replace) 

graph combine output\unemp_industry_low.gph output\unemp_industry_high.gph, graphregion(color(white))
graph display, ysize(4) xsize(6)
qui graph export "output\fig_2_adjusted_unemployment_industry.png", replace

********************************************************************************
********************************************************************************
*Data 
use "data/aggregate_main.dta", clear 
tsset municip_id year_week, weekly  

*Figure 3: Adjusted Unemployment, Variation in Shock Exposure 
tsline unemp_adj_low10 if industry_share_low ==1, lcolor(black) lpattern(solid) || ///
tsline unemp_adj_top10 if industry_share_top ==1, lcolor(black) lpattern(dash_dot) ///
ylabel(-2(1)5, labsize(small) nogrid) xlabel(3068 3097 3126 3155, labsize(small) nogrid) ///
title("", size(medium) color(black)) graphregion(color(white)) ytitle("Adjusted unemployment", size(medium)) ///
xtitle("Year, week", size(medium)) legend(size(small) symxsize(7)) ysc(titlegap(+2)) ///
xline(3130 3141, lcolor(black) lp(dash) lwidth(vthin)) legend(order(1 "Low share" 2 "High share") size(medium) symxsize(7)) || ///
(pcarrowi 2 3125 2 3130 (9) "Lockdown" 4 3145 4 3141 (3) "Reopening", color(black) mlabcolor(black))
graph display, ysize(4) xsize(6)
qui graph export "output/fig_3_adjusted_unemployment_extreme.png", replace

*Figure 4: Adjusted Unemployment and Caseworker Meetings 
binscatter meetings unemp_adj if clients >10, nquantiles(50) ytitle("Average caseworker meetings", size(medium)) xtitle("Adjusted unemployment", size(medium)) xlabel(-1(1)4, labsize(small) nogrid) ylabel(0(0.05)0.2, nogrid labsize(small)) ysc(titlegap(+3)) xsc(titlegap(+3)) mcolors(gs8) lcolors(black) 
graph display, ysize(4) xsize(6)
qui graph export "output\fig_4_adjusted_unemployment_meetings.png", replace 

*Figure 5: Weekly Caseworker Meetings, Ethnicity and the Unemployment Shock 
twoway (scatter meetings_dk year_week if island == 0 & meetings_dk <0.4 & clients_dk >10, msymbol(p) mcolor(gs10)) || ///
(lowess meetings_dk year_week if treat_1 == 0 & island == 0, lcolor(black) lwidth(medthick)) || ///
lowess meetings_dk year_week if treat_1 == 1 & island == 0, lcolor(black) lwidth(medthick)  || ///
lowess meetings_dk year_week if treat_2 == 1 & island == 0, lcolor(black) lwidth(medthick) || ///
(scatter meetings_ethnic year_week if island == 0 & meetings_ethnic <0.4 & clients_ethnic >10, msymbol(p) mcolor(gs10)) || ///
(lowess meetings_ethnic  year_week if treat_1 == 0 & island == 0 & clients_ethnic > 10, lcolor(black) lwidth(medthick) lpattern(shortdash) ) || ///
lowess meetings_ethnic  year_week if treat_1 == 1 & island == 0 & clients_ethnic > 10, lcolor(black) lwidth(medthick) lpattern(shortdash)  || ///
lowess meetings_ethnic  year_week if treat_2 == 1 & island == 0 & clients_ethnic > 10, lcolor(black) lwidth(medthick) lpattern(shortdash)  ///
xline(3130 3141, lcolor(black*0.8) lp(dash) lwidth(vthin)) ylabel(0.0(0.1)0.4, labsize(small) nogrid) xlabel(3068 3097 3126 3155, labsize(small)) ///
title("", size(medium) color(black) margin(b=3)) graphregion(color(white)) ytitle("Average meetings", size(medium)) ///
xtitle("Year, week", size(medium)) recast(line) legend(order(2 "Danish majority" 6 "Non-western minority") size(small) symxsize(7)) ysc(titlegap(+3)) ///
|| (pcarrowi 0.25 3125 0.25 3130 (9) "Lockdown" 0.3 3145 0.3 3141 (3) "Reopening", color(black) mlabcolor(black)) 
graph display, ysize(4) xsize(6)
qui graph export "output\fig_5_its_meetings.png", replace 

*Figure 6: Weekly Caseworker Meetings, Ethnicity and Shock Exposure 

*Low
twoway (scatter meetings_dk year_week if industry_share_bi ==0 & meetings_dk <0.25 & clients_dk >10, msymbol(p) mcolor(gs10)) /// 
|| (lowess meetings_dk year_week if treat_1 == 0 & industry_share_bi ==0, lcolor(black) lwidth(medthick)) ///
|| lowess meetings_dk year_week if treat_1 == 1 & industry_share_bi ==0, lcolor(black) lwidth(medthick) ///
|| lowess meetings_dk year_week if treat_2 == 1 & industry_share_bi ==0, lcolor(black) lwidth(medthick) ///
|| (scatter meetings_ethnic year_week if industry_share_bi ==0 & meetings_ethnic <0.25 & clients_ethnic >10, msymbol(p) mcolor(gs16)) ///
|| (lowess meetings_ethnic year_week if treat_1 == 0 & industry_share_bi ==0, lcolor(black) lpattern(shortdash) lwidth(medthick)) ///
|| lowess meetings_ethnic year_week if treat_1 == 1 & industry_share_bi ==0, lcolor(black) lpattern(shortdash) lwidth(medthick) ///
|| lowess meetings_ethnic year_week if treat_2 == 1 & industry_share_bi ==0, lcolor(black) lpattern(shortdash) lwidth(medthick) ///
xline(3130 3141, lcolor(black*0.8) lp(dash) lwidth(vthin)) ///
ylabel(0.0(0.05)0.25, labsize(small) nogrid) ///
xlabel(3068 3097 3126 3155, labsize(small))  ///
title("{bf:(a) Low exposure}", size(medium) color(black) margin(b=3)) ///
graphregion(color(white)) ytitle("Average meetings", size(medium)) ///
xtitle("Year, week", size(medium)) ///
recast(line) ///
ysc(titlegap(+3)) ///
legend(order(2 "Danish majority" 6 "Non-western minority") size(small) symxsize(7)) ///
|| (pcarrowi 0.2 3125 0.2 3130 (9) "Lockdown" 0.24 3145 0.24 3141 (3) "Reopening", color(black) mlabcolor(black)), ///
saving(output\did_low_industri_bi.gph, replace)

*High
twoway (scatter meetings_dk year_week if industry_share_bi ==1 & meetings_dk <0.25 & clients_dk >10, msymbol(p) mcolor(gs10)) ///
|| (lowess meetings_dk year_week if treat_1 == 0 & industry_share_bi ==1, lcolor(black) lwidth(medthick)) ///
|| lowess meetings_dk year_week if treat_1 == 1 & industry_share_bi ==1, lcolor(black) lwidth(medthick) ///
|| lowess meetings_dk year_week if treat_2 == 1 & industry_share_bi ==1, lcolor(black) lwidth(medthick) ///
|| (scatter meetings_ethnic year_week if industry_share_bi ==1 & meetings_ethnic <0.25 & clients_ethnic >10, msymbol(p) mcolor(gs16)) ///
|| (lowess meetings_ethnic year_week if treat_1 == 0 & industry_share_bi ==1, lcolor(black) lpattern(shortdash) lwidth(medthick)) ///
|| lowess meetings_ethnic year_week if treat_1 == 1 & industry_share_bi ==1, lcolor(black) lpattern(shortdash) lwidth(medthick) ///
|| lowess meetings_ethnic year_week if treat_2 == 1 & industry_share_bi ==1, lcolor(black) lpattern(shortdash) lwidth(medthick) ///
xline(3130 3141, lcolor(black*0.8) lp(dash) lwidth(vthin)) ///
ylabel(0.0(0.05)0.25, labsize(small) nogrid) ///
xlabel(3068 3097 3126 3155, labsize(small))  ///
title("{bf:(b) High exposure}", size(medium) color(black) margin(b=3)) ///
graphregion(color(white)) ytitle("", size(medium)) ///
xtitle("Year, week", size(medium)) ///
recast(line) ///
ysc(titlegap(+3)) ///
legend(order(2 "Danish majority" 6 "Non-western minority") size(small) symxsize(7)) ///
|| (pcarrowi 0.2 3125 0.2 3130 (9) "Lockdown" 0.24 3145 0.24 3141 (3) "Reopening", color(black) mlabcolor(black)), ///
saving(output\did_high_industri_bi.gph, replace)

*Combine the two graphs into one 
grc1leg output\did_low_industri_bi.gph output\did_high_industri_bi.gph, graphregion(color(white)) ycommon 
graph display, ysize(4) xsize(6)
qui graph export "output\fig_6_did_meetings.png", replace

********************************************************************************

*Data 
use "data/micro_duration.dta", clear 

*Figure 7: Ethnicity and Unemployment Duration 
stset spell, failure(failure==1) //Declare data to be survival data
sts test ethnicity, logrank //Conducts log-rank test
stcox i.ethnicity //Calculates the hazard ratios 

sts graph, by(ethnicity) graphregion(color(white)) plot1opts(color(gs15) lstyle(solid))  ///
ytitle("Propability of staying unemployed", size(medium)) xtitle("Weeks to event", size(medium)) ///
legend(order(1 "Danish majority" 2 "Non-western minority") ring(0) pos(2) col(1) region(lstyle(none)) symxsize(5)) ///
xlabel(1(4)30, labsize(small) nogrid) ylabel(0(0.2)1, labsize(small) nogrid) ///
title("", size(medium) color(black)) xsc(titlegap(+1)) ysc(titlegap(+3)) /// 
note("Hazard ratio, 0.70 (0.66-0.73)" "P=0.00 by log-rank test", ring(0) margin(medium))
qui graph export "output\fig_7_survival.png", replace

********************************************************************************

*Data
use "data/micro_main.dta", clear 

*Table 1 
eststo i1: reg meeting treat_1##c.time_w11##ethnic if sample == 1, cluster(municip_id) 
eststo i2: reg meeting treat_1##c.time_w11##ethnic spell_seq c.education c.gender age sick_19 employ_19 if sample == 1, cluster(municip_id)
eststo i3: reg meeting treat_2##c.time_w22##ethnic if sample == 1, cluster(municip_id) 
eststo i4: reg meeting treat_2##c.time_w22##ethnic spell_seq c.education c.gender age sick_19 employ_19 if sample == 1, cluster(municip_id)
 
esttab i1 i2 using output\tab_1_w11.rtf, replace obslast se b(3) sfmt(2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) noomitted nobaselevels nogaps title(Table 1: Caseworker meeting, ethnicity and the unemployment shock) varwidth(40)

esttab i3 i4 using output\tab_1_w22.rtf, replace obslast se b(3) sfmt(2) star(+ 0.10 * 0.05 ** 0.01 *** 0.001) noomitted nobaselevels nogaps title(Table 1: Caseworker meeting, ethnicity and the unemployment shock) varwidth(40)

*Table 2
eststo d1: reg meeting treat_1##industry_share_bi##ethnic if benefit == 3, cluster(municip_id)
eststo d2: reg meeting treat_1##industry_share_bi##ethnic spell_seq c.education c.gender age sick_19 employ_19 if benefit == 3, cluster(municip_id)
eststo d3: reg meeting treat_2##industry_share_bi##ethnic if benefit == 3, cluster(municip_id)
eststo d4: reg meeting treat_2##industry_share_bi##ethnic spell_seq c.education c.gender age sick_19 employ_19 if benefit == 3, cluster(municip_id)

*Esttab
esttab d1 d2 using output\tab_2_w11.rtf, replace nobaselevels nogaps title(Table 2: Caseworker meeting, ethnicity and shock exposure) se b(3) noomitted obslast varwidth(40) star(+ 0.10 * 0.05 ** 0.01 *** 0.001)

esttab d3 d4 using output\tab_2_w22.rtf, replace nobaselevels nogaps title(Table 2: Caseworker meeting, ethnicity and shock exposure) se b(3) noomitted obslast varwidth(40) star(+ 0.10 * 0.05 ** 0.01 *** 0.001)

********************************************************************************

log close 
translate "log_manuscript.smcl" "log_manuscript.pdf" 

********************************************************************************






